package com.rong.juc_test.juc_p6_p7;

import java.util.concurrent.TimeUnit;

/**
 * 守护线程 用户线程演示
 */
public class DaemonDemo {
    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始运行"
                    +(Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
//            while (true){
//                // 循环检查线程是否结束
//            }
        },"a");
//        a.setDaemon(true); // 设置守护线程
        a.start();

        Thread b = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "开始运行"
                    +(Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
            while (true){
                // 循环检查线程是否结束
            }
        },"b");
        b.setDaemon(true); // 设置守护线程
        b.start();
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "运行结束");

    }
}
